﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 数组练习
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //int[] arr = new int[5];
            //for (int i = 0; i < arr.Length; i++)
            //{
            //    Console.WriteLine($"请输入第{i + 1}个数字");
            //    arr[i] = Convert.ToInt32(Console.ReadLine());
            //}

            //Console.Write("\n输入的5个数字为：");
            //for (int i = 0; i < arr.Length; i++)
            //{
            //    Console.Write(arr[i]);

            //    if (i < arr.Length - 1)
            //        Console.Write(", ");
            //}

            //int sum = 0;
            //foreach (var num in arr)
            //{
            //    sum += num;
            //}
            //Console.WriteLine("\n\n5个数字的和为：" + sum);

            //Console.WriteLine("\n5个数字的平均数为：" + (sum / 5));

            //int[] arr = { 8, 2, 1, 0, 3 };
            //int[] index = { 2, 0, 3, 2, 4, 0, 1, 3, 2, 3, 3 };
            //string tel = "";
            //foreach(int i in index)
            //{
            //    tel += arr[i];
            //}
            //Console.WriteLine(tel);
            //Console.ReadKey();

            int N = 5;
            Console.WriteLine("----------------------------");
            Console.WriteLine("  欢迎使用简易超市管理系统");
            Console.WriteLine("----------------------------");
            bool started = true;
            string[] names = new string[N];
            double[] prices = new double[N];
            int count = 0;
            do
            {
                Console.WriteLine("\n请选择操作: ");
                Console.WriteLine("1.录入商品");
                Console.WriteLine("2.查看商品");
                Console.WriteLine("3.退出系统");
                int num = Convert.ToInt32(Console.ReadLine());
                switch (num)
                {
                    case 1:
                        while (true)
                        {
                            Console.Write("\n请输入商品名称: ");
                            string name = Console.ReadLine();
                            names[count] = name;
                            Console.Write("请输入商品价格: ");
                            double price = Convert.ToDouble(Console.ReadLine());
                            prices[count] = price;
                            count++;
                            Console.WriteLine("是否选择重新录入? y | n");
                            string flag = Console.ReadLine();
                            if (!(flag == "y"))
                            {
                                break;
                            }
                        }
                        break;
                    case 2:
                        Console.WriteLine("\n商品名称\t商品价格");
                        for (int i = 0; i < count; i++)
                        {
                            Console.WriteLine($"{names[i]}\t{prices[i]}");
                        }
                        break;
                    case 3:
                        Console.WriteLine("感谢使用，再见!");
                        started = false;
                        break;
                    default:
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("\n输入的操作编号不存在！");
                        Console.ResetColor();
                        break;
                }

            }
            while (started);

        }
    }
}
